package com.xyq.fs.task;

import javafx.application.Platform;

public class AfRunner extends Thread
{
	int delay = 1;
	Runnable r;
	
	public AfRunner(int delay)
	{
		this.delay = delay;
	}
	
	public void execute(Runnable r)
	{
		this.r = r;
		start();
	}

	@Override
	public void run()
	{
		if(delay > 0)
		{
			try {
				sleep(delay);
			}catch(Exception e) {}
			
		
			if(this.r != null)
			{
				Platform.runLater (r );
			}
		}
	}
	
	///////////////////////////////
	// delay: ms 
	public static void runLater(int delay, Runnable r)
	{
		AfRunner adr = new AfRunner(delay);
		adr.execute(r);
	}	
}
